var express = require('express');
var superagent = require('superagent');
var router = express.Router();

/* GET home page. */
router.get('/index', function(req, res, next) {
  var thisUrl = req.url;
  var isLalocal = req.query.isapp;
  var shareUrl = encodeURIComponent((global.browserURL + thisUrl).split('#')[0]);
console.log(global.wechatURL + '/wechat_api/jsconfig?url=' + shareUrl);
    superagent
        .get(global.wechatURL + '/wechat_api/jsconfig?url=' + shareUrl)
        .end(function(err, res1) {
            if (res1 !== undefined && res1.body) {
                res.render('index',{'wxConfig':res1.body,
                'isLalocal':isLalocal,
                'browserURL':global.browserURL
              });
            } else {
                console.error('微信授权错误。');
                logger.error('微信授权错误。');

                res.render('error', {});
            }
        });
});

module.exports = router;
